package leetcode.editor.week.week302;

import java.util.HashMap;
import java.util.Map;

public class Solution6120 {
    // hash表:https://leetcode.cn/problems/maximum-number-of-pairs-in-array/
    public int[] numberOfPairs(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int count = 0;
        int count1 = 0;
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }

        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            while (entry.getValue() >= 2) {
                map.put(entry.getKey(), map.getOrDefault(entry.getKey(), 0) - 2);
                count++;
            }
        }

        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if (entry.getValue() != 0 && entry.getValue() < 2) {
                count1++;
            }
        }

        return new int[]{count, count1};
    }
}
